package com.google.code.avajhelpdesk.entities;

import org.hibernate.proxy.HibernateProxy;

public class Entities {

	@SuppressWarnings("unchecked")
	public static <T extends DomainModel> Class<T> getEntityClass(T entity) {
        if (entity instanceof HibernateProxy) {
            HibernateProxy proxy = (HibernateProxy) entity;
            return (Class<T>) proxy.getHibernateLazyInitializer()
                .getPersistentClass();
        } else {
            return (Class<T>) entity.getClass();
        }
	}
}
